package com.cmsr.hdpf

import com.cmsr.hdpf.etl.TaskEngine
import org.apache.flink.api.java.utils.ParameterTool

object App {
    def main(args: Array[String]): Unit = { // Unit 代表无返回值？
        println("hello,world! 程序主入口......")
        
        val params = createParameterTool(args)
        constant.task = params.get("task", "parse")
        constant.source = params.get("source", "kafka")
        constant.sink = params.get("sink", "kafka")
        constant.parser = params.get("parser", "gaotie")
        constant.debug = params.get("debug", "true")
        constant.windowSize = params.get("windowSize", "2")
        
        
        println("task:", constant.task)
        println("source:", constant.source)
        println("sink:", constant.sink)
        println("parser:", constant.parser)
        println("windowSize:", constant.windowSize)
        
        TaskEngine.run(constant.task, constant.source, constant.sink, constant.parser, constant.debug, constant.windowSize.toInt)
        
    }
    
    def createParameterTool(args: Array[String]): ParameterTool = {
        //-D 参数覆盖, args参数覆盖配置文件参数
        val parameterTool: ParameterTool = ParameterTool.fromPropertiesFile(Thread.currentThread().getContextClassLoader().getResourceAsStream("application.conf")) // 配置文件参数
                .mergeWith(ParameterTool.fromArgs(args)) // 命令行参数
                .mergeWith(ParameterTool.fromSystemProperties()) // 系统属性参数
        parameterTool
    }

}
package object constant {
    var task: String = _ // 任务名
    var source: String = _ // 数据源
    var sink: String = _ // 输出源
    var parser: String = _ // 解析任务对象名
    var debug: String = _
    var windowSize: String = _ // 设置窗口时间，单位分钟
}


